var id = getvl("id");
var nuber="";
   $(function(){
   	   if(id!=''){
   	   	dingdandaifukuan(id);
   	   }else{
   	   	alert(".....失败");
   	   }
   });
function dingdandaifukuan(id){
	$.ajax({
		url: urlcore + "/api/order/selectOne2?id="+id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				var da=data.data;
				  var zhuantai="";
		                if(da.status==0){
							zhuantai="未付款";
						}else if(da.status==1){
							zhuantai="支付成功";
						}else if(da.status==2){
							zhuantai="确认收货";
						}else if(da.status==3){
							zhuantai="已评价";
						}else if(da.status==4){
							zhuantai="客户删除";
						}else if(da.status==5){
							zhuantai="商家删除";
						}else if(da.status==6){
							zhuantai="都删除";
						}else if(da.status==7){
							zhuantai="订单取消";
						}else if(da.status==8){
							zhuantai="退款申请中";
						}else if(da.status==9){
							zhuantai="退款失败";
						}else if(da.status==10){
							zhuantai="退款成功";
						}
			//物流信息	
			var wuliud="";
			///var gmtDatetime = new Date(data.data.gmtDatetime).pattern("yyyy-MM-dd hh:mm:ss");
				var shijian=data.data.gmtDatetime.replace("-","/");
				var shijian2=shijian.replace("-","/");
				$("#shijian").val(shijian2);
				
			if(da.express!=null){
		 wuliud+='<a href="../buy/12.8.5buy_dingdan_wuliu.html?orderNumber='+da.id+'">'+
	'<dl>'+
			'<dt>'+da.express.companyName+'</dt>'+
			'<dd>单号：'+da.express.expressNumber+'</dd>'+
		'</dl>'+
	'</a>';
			}else{
		wuliud+='<a href="#">'+
		'<dl>'+
			'<dt>********</dt>'+
			'<dd>*********</dd>'+
		'</dl>'+
	'</a>';
			}
			$("#wuliuxinxi").html(wuliud);			
     var dingdanzhuang='<h5><span>订单状态</span><em>'+zhuantai+'</em></h5>'+
'	<ul>'+
'		<li>'+
'			<span>订单编号</span>'+
'			<em id="biao1">'+da.orderNumber+'</em>'+
'			<i class="copy">复制订单号</i>'+
'		</li>'+
'		<li>'+
'			<span>下单时间</span>'+
'			<em>'+da.gmtDatetime+'</em>'+
'		</li>'+
'		<li>'+
'			<span>买家留言</span>';
             if(da.remark!=null){
        dingdanzhuang+='			<em>'+da.remark+'</em>';
             }else{
             	    dingdanzhuang+='<em></em>';
             }

 dingdanzhuang+='		</li>'+
'	</ul>';

       var fahuoxinxi='<div class="sell_detail_dz">'+
        '<span>'+da.address.userName+'</span>'+
'		<em>'+da.address.userPhone+'</em>'+
'		<i class="fuzhidz">复制地址</i>'+
'	</div>'+
'	<p id="dizhixinxi">'+da.address.province+'·'+da.address.city+'·'+da.address.county+'.'+da.address.address+'</p>';
     
     
     var maijiaxinxi='<h6>买家:'+da.user.userName+'</h6>'+
'	<div class="fr">'+
'		<a href="sms:'+da.user.phone+'">'+
'			<img src="../images/sell_chat.png" />'+
'		</a>'+
'		<a href="tel:'+da.user.phone+'">'+
'			<img src="../images/sell_tel.png" />'+
'		</a>'+
'	</div>';
 var shangpingxinxi="";
 var danjia="";
       $.each(da.goodsCarList, function(y,q) {
			 shangpingxinxi+='<div class="clearfix tuwen">'+
'    	<a href="../7.0.0goods_detail.html?id='+q.goods.id+'">'+
'	        <div class="tuwen-img fl">'+
'	            <img onerror="errorImg(this)" src="'+q.goods.coverUrl+'" width="75" height="75">'+
'	        </div>'+
'	        <div class="tuwen-wenzi">'+
'	            <h5 class="wuye_h01">'+q.goods.goodsTitle+'</h5>'+
'	            <div class="wuye_div01">产品质量均有保障</div>'+
'	        </div>'+
'        </a>'+
'    </div>';
		 $.each(q.myStockList,function(y,n){
			shangpingxinxi += ' <div class="dingdan_fenlei clearfix">' +
 								'    	<ul class="fl">' +
 								'    		<li>颜色：<span>'+n.colour.colourName+'</span></li>'+
'    		<li>尺码：<span>'+n.size.sizeName+'</span></li>'+
'    		<li>单价：<span>'+q.packRate+'元/件</span></li>'+'    	</ul>' +
 								'    	<div class="fr">' +
 								'    		<h5>' + ((q.packRate*n.saleNum).toFixed(2))+ '元</h5>' +
 								'    		<h6>' + n.saleNum + '件</h6>' +
 								'    	</div>' +
 								'    </div>';
			 });
			 });
			 
          var shangpingxinxiss='<div class="sell_detail">'+
'    	<h5>共<em>'+da.goodsNumber+'</em>件<span>(含运费'+da.freightMoney+'元)</span></h5>'+
'    	<h6>实收费：<span>&yen;'+da.payMoney+'</span></h6>'+
'    </div>';
         $("#dingdanzhuang").append(dingdanzhuang);
            $("#fahuoxinxi").append(fahuoxinxi);
               $("#shangpingxinxi").append(shangpingxinxi);
               $("#maijiaxinxi").append(maijiaxinxi);
                $("#shangpingxinxiss").append(shangpingxinxiss);
                nuber=da.orderNumber;
            var dingdna='<a href="javascript:void(0);" onclick="tuifei(this)" id="'+da.orderNumber+'" class="P-tuifei">退费</a>'+
            '<input type="hidden" value="'+da.freightMoney+'" id="mails">'+
'<input type="hidden" value="'+da.payMoney+'" id="Ordertotalprice">'+ 
			'<a href="36.1.0sell_dingdan_daifahuo_fahuotianxie.html?ids='+da.id+'">修改物流</a>'+
			'<a href="../buy/12.8.5buy_dingdan_wuliu.html?orderNumber='+da.id+'">订单跟踪</a>'+
			'<a href="javascript:void(0);"  name="'+da.orderNumber+'" onclick="tixingshouhuo(this)" class="sell_detail_footer_curr">提醒收货</a>';
                $("#selldingdan").append(dingdna);
                $(function(){
                	  // 取消订单
    // 弹出
    $(".P-tuifei").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".sell-xiugai2").show();
    })
    //点击关闭
    $(".show2_anniu span").on('click',function(){
        $(".sell-xiugai2").hide();
        $("#mask").remove();
    }) 
    
    
           	 var copyBtn = document.querySelector('.copy')

  // 点击的时候调用 copyTextToClipboard() 方法就好了.
  copyBtn.onclick = function() {
  	var leirongs=$("#biao1").html();
    copyTextToClipboard(leirongs);
  }
           	 var copyBtndz = document.querySelector('.fuzhidz')
  // 点击的时候调用 copyTextToClipboard() 方法就好了.
  copyBtndz.onclick = function() {
  	var leirongs=$("#dizhixinxi").html();
    copyTextToClipboard(leirongs);
  }


  function copyTextToClipboard(text) {
   var textArea = document.createElement("textarea")
    textArea.style.position = 'fixed'
    textArea.style.top = 0
    textArea.style.left = 0
    textArea.style.width = '2em'
    textArea.style.height = '2em'
    textArea.style.padding = 0
    textArea.style.border = 'none'
    textArea.style.outline = 'none'
    textArea.style.boxShadow = 'none'
    textArea.style.background = 'transparent'
    textArea.value = text
    document.body.appendChild(textArea)
    textArea.select()
    try {
      var msg = document.execCommand('copy') ? '成功' : '失败'
      console.log('复制内容 ' + msg)
    } catch (err) {
      console.log('不能使用这种方法复制内容')
    }
  document.body.removeChild(textArea)
       }
          
             // 退费
    // 弹出
    $(".P-tuifei").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".sell-xiugai2").show();
    })
    //点击关闭
    $(".show2_anniu span").on('click',function(){
        $(".sell-xiugai2").hide();
        $("#mask").remove();
    }) 
           
    
    
                })
                
                
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	

	
}

/*
10 <textarea cols="20" rows="10" id="biao1">用户定义的代码区域</textarea>
11 <input type="button" onClick="copyUrl2()" value="点击复制代码" />

*/
/*function fuzhidizhi(){
	var Url2=$("#dihzi");
	 Url2.select(); 
	document.execCommand("Copy"); // 执行浏览器复制命令
	 alert("已复制好，可贴粘。");
}
*/

function tuifei(te){
	   $("#tuifeioderid").val("");
  var tuifeioderid=$(te).attr("id");
   $("#tuifeioderid").val(tuifeioderid);
	
	
	$("#ordermoylie").html("");
   $("#yuns").html("");
   var yuns=$(te).next().val();
   
   var Ordertotalprice=$(te).next().next().val();
   $("#ordermoylie").html(Ordertotalprice);
   $("#yuns").html(yuns);
}



  function fuzhidizhi(){  
        var clipBoardContent="拷贝成功！";  
        var clipBoard_Error="抱歉！您现在的浏览器不支持自动拷贝功能，请手动拷贝链接发给好友";  
        if(window.clipboardData){  
             var url = $("#dihzi").html();  
             window.clipboardData.setData("Text",url);  
            alert(clipBoardContent);  
        }else{  
             alert(clipBoard_Error);  
        }  
    }   
    






//退费
function tuifeiss(){
	var tuifei=parseFloat($("#tuifeijinge").val());
	var tuifeioderid=$("#tuifeioderid").val();
	var tui=$("#yuns").html();
	if(tuifeioderid!=null&& tuifeioderid!=''){
		if(tuifei>0){
if(uuuuid!=""){
   	  $.ajax({
      url: urlcore+"/api/order/updatePrice2?orderNumber="+tuifeioderid+"&userid="+uuuuid+"&payMoney="+tuifei+"&freightMoney="+tui,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//alert("成功")
					var lujing=window.location.href;
				window.location.href=lujing;
				}
			},
			error: function() {
				alert("error");
			}
		});
			}
	}
	}
}




function tixingshouhuo(te){
	var tixing=$(te).attr("name");
   	  $.ajax({
      url: urlcore+"/api/user/remindingTheReceipt?orderNumber="+tixing,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
                   alert("已提醒该用户");
				}else{
					alert(data.msg);
				}
			},
			error: function() {
				alert("error");
			}
		});
}
